/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import view.FunctionMenu;
import view.ViewManager;

/**
 *
 * @author Kvest
 */
public class Order3 extends Order2 {
    // ID Партнера
    protected int partnerID;
    // Name Партнера
    protected String partnerName;
    // Краткое описание - он отобразится при выводе списка заказов
    protected String orderShortDesc;
    //  Полное описание - при просмотре заказов
    protected String orderFullDesc;
    //  Полное описание для предварительных заказов
    protected String orderPrelimFullDesc;
    
    public Order3(int _orderID)
    {
        super(_orderID);
        
        partnerID = -1;
        orderShortDesc = "";
        orderFullDesc = "";
        orderPrelimFullDesc = "";

    }
    
    public Order3(byte[] data) throws IOException
    { 
        this(-1);
       
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);

        try
        {  
            readFields(dis);
        }
        finally
        {
            try
            {
                dis.close();
                bais.close();
            }catch(Exception ex){}
        }       
    }
    
    protected void readFields(DataInputStream dis) throws IOException {
        //partnerID;
        partnerID = dis.readInt();
        
        //partnerName;
        partnerName = dis.readUTF();
        
        //orderShortDesc;
        orderShortDesc = dis.readUTF();
        
        //orderFullDesc;
        orderFullDesc = dis.readUTF(); 
        
        //orderPrelimFullDesc;
        orderPrelimFullDesc = dis.readUTF(); 
                
        super.readFields(dis);        
    }
    
    protected void writeFields(DataOutputStream dos) throws IOException {
        //partnerID;
        dos.writeInt(partnerID);
        
        //partnerName;
        dos.writeUTF(partnerName);
        
        //orderShortDesc;
        dos.writeUTF(orderShortDesc);
        
        //orderFullDesc;
        dos.writeUTF(orderFullDesc);
        
        //orderPrelimFullDesc;
        dos.writeUTF(orderPrelimFullDesc);
        
        super.writeFields(dos);
    }
    
    public void copy(Order src) {
        super.copy(src);
        
        if (src instanceof Order3)
        {
            //partnerID;
            partnerID = ((Order3)src).partnerID;
        
            //partnerName;
            partnerName = ((Order3)src).partnerName;

            //orderShortDesc;
            orderShortDesc = ((Order3)src).orderShortDesc;

            //orderFullDesc;
            orderFullDesc = ((Order3)src).orderFullDesc;

            //orderPrelimFullDesc;
            orderPrelimFullDesc = ((Order3)src).orderPrelimFullDesc;
        }       
    } 
    
    public String getPreOrderDetails() {
        return orderPrelimFullDesc;
    }
    
    public String getDetailsText(boolean fullData, String type) {
        //Если для Черновцов - возвращаем в особом формате
        if (ViewManager.getViewManager().getFunctionMenuType() == FunctionMenu.CHERNOVTSI_TYPE) {
            return getChernovtsiDetailsText();
        } else {
            return orderFullDesc;
        }
    } 
    
    public String getShortDescription() {
        return orderShortDesc;
    }

    public String getOrderFullDesc() {
        return orderFullDesc;
    }

    public void setOrderFullDesc(String orderFullDesc) {
        this.orderFullDesc = orderFullDesc;
    }

    public String getOrderPrelimFullDesc() {
        return orderPrelimFullDesc;
    }

    public void setOrderPrelimFullDesc(String orderPrelimFullDesc) {
        this.orderPrelimFullDesc = orderPrelimFullDesc;
    }

    public String getOrderShortDesc() {
        return orderShortDesc;
    }

    public void setOrderShortDesc(String orderShortDesc) {
        this.orderShortDesc = orderShortDesc;
    }

    public int getPartnerID() {
        return partnerID;
    }

    public void setPartnerID(int partnerID) {
        this.partnerID = partnerID;
    }

    public String getPartnerName() {
        return partnerName;
    }

    public void setPartnerName(String partnerName) {
        this.partnerName = partnerName;
    }
}
